﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Reflexive.IO;
using System.Management;

namespace Reflexive.IO.Examples
{
    class Program
    {
        //http://www.infoq.com/articles/no-reliable-messaging
        static void Main(string[] args)
        {
            Console.WriteLine(@"
 Add the section below to the Web.config on the Machine
 from which you are querying events. The example uses the local
 machine by default. You can then request a page under your website
 or recylce IIS to capture the resulting event stream.

    <system.web>
    <healthMonitoring>
      <rules>
        <add
         name=""Using Wmi""
         eventName=""All Events""
          provider=""WmiWebEventProvider""
          profile=""Critical""/>
      </rules>
    </healthMonitoring>
    <compilation defaultLanguage=""c#"" debug=""true"" targetFramework=""4.0"" />
    </system.web>");

            WMIReader<ManagementBaseObjectConverter, string> WMIreader = new WMIReader<ManagementBaseObjectConverter, string>(String.Format("\\\\{0}\\root\\aspnet", Environment.MachineName), "select * from BaseEvent");

#if ZeroMQ
            ZeroWriter<ByteConverter, string> Zwriter = new ZeroWriter<ByteConverter, string>(new[] { "tcp://127.0.0.1:5000" });
            using (WMIreader.Subscribe(Zwriter))
            {
                ZeroReader<StringConverter, string> Zreader = new ZeroReader<StringConverter, string>(new[] { "tcp://127.0.0.1:5000" });
                using (Zreader.Subscribe(Console.WriteLine))
                {
                    WMIreader.Start();
                    Zreader.Start();
                    Zwriter.Start();
                    Console.ReadLine();
                }
            }
            Console.ReadLine();
#endif

#if MSMQ
            MSMQWriter<string> MQwriter = new MSMQWriter<string>(@".\private$\reflexive");
            using (WMIreader.Subscribe(MQwriter))
            {

                using (MSMQReader<string> MQreader = new MSMQReader<string>(@".\private$\reflexive"))
                {
                    using (MQreader.Subscribe(Console.WriteLine))
                    {
                        MQreader.Start();
                        MQwriter.Start();
                        WMIreader.Start();
                        Console.ReadLine();
                    }
                }

            }
#endif

        }
    }
}
